package com.hermit.alaskagulfknife4j.entity;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author hermit
 * @data 2021/6/16
 * 统一返回类
 */
@Data
public class ResultBO<T> {

    @ApiModelProperty(required = true, notes = "返回数据")
    private T content;

    @ApiModelProperty(required = true, notes = "返回成功与否", example = "true")
    private boolean succeed = true;

    @ApiModelProperty(required = true, notes = "结果码", example = "200")
    private int code = 0;

    @ApiModelProperty(required = true, notes = "返回信息说明", example = "SUCCESS")
    private String msg;

    public ResultBO(T content) {
        this.content = content;
    }

    public ResultBO(boolean succeed, int code, String msg, T content) {
        this.succeed = succeed;
        this.code = code;
        this.msg = msg;
        this.content = content;
    }

    public ResultBO(boolean succeed, int code, String msg) {
        this.succeed = succeed;
        this.code = code;
        this.msg = msg;
    }

    public ResultBO() {

    }

    public static <T> ResultBO<T> success(T content) {
        return new ResultBO<T>(content);
    }

    public static ResultBO success() {
        return new ResultBO();
    }

    public static ResultBO fail(int code, String msg) {
        return new ResultBO(false, code, msg);
    }

    public static ResultBO fail(String msg) {
        return new ResultBO(false, -1, msg);
    }

    public static ResultBO fail() {
        return fail("fail");
    }
}
